package com.example.demo.stringDemo;

import cn.hutool.core.comparator.CompareUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.PageUtil;
import org.junit.Test;

import java.util.Date;
import java.util.List;

/**
 * @author pengyifeng
 * @version 5.0
 * @ClassName ConvertTest.java
 * @Description TODO
 * @createTime 2021年04月29日 11:21:00
 */
public class ConvertTest {

    @Test
    public void t1(){
        //数字转换为字符串
        int a=1;
        String s = Convert.toStr(a);
        System.out.println(s);

        //[1, 2, 3, 4, 5]
        long[] b={1,2,3,4,5};
        String s1 = Convert.toStr(b);
        System.out.println(s1);

        //转换为指定类型数组
        String[] bs = { "1", "2", "3", "4" };
        Integer[] integers = Convert.toIntArray(bs);
        System.out.println(integers);

        long[] bl={ 1,2,3,4};
        Integer[] integers1 = Convert.toIntArray(bl);
        System.out.println(integers1);

        //转换为日期对象：
        String dateStr = "2017-05-06";
        Date date = Convert.toDate(dateStr);
        System.out.println(date);

        //转换为集合
        Object[] os = {"a", "你", "好", "", 1};
        List<?> convert = Convert.convert(List.class, os);
        List<?> objects = Convert.toList(convert);
        System.out.println(objects);
    }

    @Test
    public void t2(){
        int compare = CompareUtil.compare(1, 2);
        int compare2 = CompareUtil.compare(2, 1);
        int compare3 = CompareUtil.compare(null, 1);
        System.out.println(compare);
        System.out.println(compare2);
        System.out.println(compare3);

    }
}
